package com.hongkzh.www.other.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.hongkzh.www.look.enterprise.userinfo.model.bean.UserInfo;

/**
 * @Title SharedPreferencesUtil.java
 * @Description:保存用户信息
 * @Company:cnfol
 * @author: ChenYongLiang
 * @date 2015-10-12下午3:57:36
 */
public class SharedPreferencesUtil {
    private SharedPreferences sp;
    private Context context;

    public SharedPreferencesUtil(Context context) {
        this.context = context;
    }

    /*
     * 保存用户信息
     */
    public void saveUserInfo(UserInfo userInfo) {
        sp = context.getSharedPreferences("USERINFO", Context.MODE_PRIVATE);
        sp.edit().putString("LoginUid", userInfo.getLoginUid()).apply();
        sp.edit().putString("userName", userInfo.getUserName()).apply();
        sp.edit().putString("realName", userInfo.getRealName()).apply();
        sp.edit().putString("nickName", userInfo.getNickName()).apply();
        sp.edit().putString("status", userInfo.getStatus()).apply();

//        sp.edit().putString("iszhibo", userInfo.getIszhibo()).apply();
//        sp.edit().putString("keystr", userInfo.getKeystr()).apply();
//        sp.edit().putString("loginTime", userInfo.getLoginTime()).apply();
//        sp.edit().putString("money", userInfo.getMoney()).apply();
//        sp.edit().putString("email", userInfo.getEmail()).apply();
//        sp.edit().putString("mobile", userInfo.getMobile()).apply();
//        sp.edit().putString("isagent", userInfo.getIsagent()).apply();
//        sp.edit().putString("checkCode", userInfo.getCheckCode()).apply();
//        sp.edit().putString("headurl", userInfo.getHeadurl()).apply();
//        sp.edit().putBoolean("islogin", userInfo.getIsLogin()).apply();
//        sp.edit().putString("token", userInfo.getToken()).apply();
//        sp.edit().putString("userStatus", userInfo.getUserStatus()).apply();
//        sp.edit().putString("company", userInfo.getCompany()).apply();
//        sp.edit().putString("position", userInfo.getPosition()).apply();
//        sp.edit().putString("summary", userInfo.getSummary()).apply();
//        sp.edit().putString("lable", userInfo.getLable()).apply();
//        sp.edit().putString("aliPayAccount", userInfo.getAliPayAccount()).apply();
//        sp.edit().putString("Authentication", userInfo.getAuthentication()).apply();
//        sp.edit().putString("careNum", userInfo.getCareNum()).apply();
//        sp.edit().putString("caredNum", userInfo.getCaredNum()).apply();
//        sp.edit().putString("friendNum", userInfo.getFriendNum()).apply();
//        sp.edit().putString("authName", userInfo.getAuthName()).apply();
//        sp.edit().putString("authPicture", userInfo.getAuthPicture()).apply();
//        sp.edit().putString("AuthStatus", userInfo.getAuthStatus()).apply();
//        sp.edit().putString("LiveProductID", userInfo.getLiveProductID()).apply();
//        sp.edit().putString("bigAuthPicture", userInfo.getbigAuthPicture()).apply();
//        sp.edit().putInt("roomID", userInfo.getRoomID()).apply();
//        sp.edit().putInt("idStatus", userInfo.getIdStatus()).apply();
//        sp.edit().putString("userSig", userInfo.getUserSig()).apply();
//        sp.edit().putString("SourceType", userInfo.getSourceType()).apply();
//        sp.edit().putString("Sex", userInfo.getSex()).apply();
//        sp.edit().putString("identityNumber", userInfo.getIdentityNumber()).apply();
//        sp.edit().putString("EndValidDate", userInfo.getEndValidDate()).apply();
//        sp.edit().putString("PointValue", userInfo.getPointValue()).apply();
//        sp.edit().putString("Cache", userInfo.getCache()).apply();
//        sp.edit().putString("MarketIsOpenAccount", userInfo.getMarketIsOpenAccount()).apply();
        //        sp.edit().putBoolean("IsRtmp", userInfo.isRtmp()).apply();
        //        sp.edit().putString("PushUrl", userInfo.getPushUrl()).apply();
    }

    /*
     * 获取用户信息
     */
    public UserInfo getUserInfo() {
        sp = context.getSharedPreferences("USERINFO", Context.MODE_PRIVATE);
        UserInfo userInfo = new UserInfo();
        userInfo.setLoginUid(sp.getString("LoginUid", null));
        userInfo.setUserName(sp.getString("userName", null));
        userInfo.setRealName(sp.getString("realName", null));
        userInfo.setNickName(sp.getString("nickName", null));
        userInfo.setStatus(sp.getString("status", null));
//        userInfo.setIszhibo(sp.getString("iszhibo", null));
//
//        userInfo.setKeystr(sp.getString("keystr", null));
//        userInfo.setLoginTime(sp.getString("loginTime", null));
//        userInfo.setMoney(sp.getString("money", null));
//        userInfo.setEmail(sp.getString("email", null));
//        userInfo.setMobile(sp.getString("mobile", null));
//        userInfo.setIsagent(sp.getString("isagent", null));
//        userInfo.setCheckCode(sp.getString("checkCode", null));
//        userInfo.setHeadurl(sp.getString("headurl", null));
//        userInfo.setIsLogin(sp.getBoolean("islogin", false));
//        userInfo.setToken(sp.getString("token", null));
//        userInfo.setUserStatus(sp.getString("userStatus", null));
//        userInfo.setCompany(sp.getString("company", null));
//        userInfo.setPosition(sp.getString("position", null));
//        userInfo.setSummary(sp.getString("summary", null));
//        userInfo.setLable(sp.getString("lable", null));
//        userInfo.setAliPayAccount(sp.getString("aliPayAccount", null));
//        userInfo.setAuthentication(sp.getString("Authentication", null));
//        userInfo.setCareNum(sp.getString("careNum", null));
//        userInfo.setCaredNum(sp.getString("caredNum", null));
//        userInfo.setFriendNum(sp.getString("friendNum", null));
//        userInfo.setAuthName(sp.getString("authName", null));
//        userInfo.setAuthPicture(sp.getString("authPicture", null));
//        userInfo.setAuthStatus(sp.getString("AuthStatus", null));
//        userInfo.setLiveProductID(sp.getString("LiveProductID", null));
//        userInfo.setbigAuthPicture(sp.getString("bigAuthPicture", null));
//        userInfo.setRoomID(sp.getInt("roomID", -1));
//        userInfo.setUserSig(sp.getString("userSig", null));
//        userInfo.setIdStatus(sp.getInt("idStatus", -1));
//        userInfo.setSourceType(sp.getString("SourceType", "0"));
//        userInfo.setSex(sp.getString("Sex", "1"));//性别  0 男 1 女
//        userInfo.setEndValidDate(sp.getString("EndValidDate", ""));//设置身份证过期时间
//        userInfo.setIdentityNumber(sp.getString("identityNumber", "1"));//身份证号
//        userInfo.setPointValue(sp.getString("PointValue", "0"));//助力值
//        userInfo.setCache(sp.getString("Cache", "0"));
//        userInfo.setMarketIsOpenAccount(sp.getString("MarketIsOpenAccount", "0"));
        //        userInfo.setRtmp(sp.getBoolean("IsRtmp", false));//获取视频直播室是否是rtmp推流
        //        userInfo.setPushUrl(sp.getString("PushUrl", ""));//获取rtmp推流地址
        return userInfo;
    }

    /*
     * 删除偏好文件
     */
    public void deleteSp(String name) {
        sp = context.getSharedPreferences(name, Context.MODE_PRIVATE);
        sp.edit().clear().apply();
    }
}
